<?php $this->renderPartial('//common/header_jumbotron');?>
<div id="container-main" class="container">
    <div class="row">
        <div id="post-view" class="col-md-18">
            <ol class="breadcrumb">
                <li><i class="fa fa-home"></i> <a href="<?php echo $this->baseUrl?>"><?php echo $this->siteName?></a></li>
                <li><a href="<?php echo $post->catParent->url?>"><?php echo $post->catParent->name?></a></li>
                <li class="active"><a href="<?php echo $post->cat->url?>"><?php echo $post->cat->name?></a></li>
            </ol>
            <?php if($post->checkUserPermisstion()):?>
                <div class="pull-right marginleft5">
                    <a rel="tooltip" href="<?php echo $post->getUrl('update')?>" title="Sửa bài" style="text-decoration: none;"><i class="fa fa-edit fa-2x"></i></a>
                </div>
            <?php endif?>
            <h1><a class="text-color" href="<?php echo $post->url?>"><?php echo $post->title?></a></h1>

            <div id="header-info" class="well simple">
                <div class="row">
                    <div class="col-sm-8 user">
                        <div class="row">
                            <div class="col-xs-10 avatar">
                                <a href="#">
                                    <img class="thumbnail marginbottom10" src="<?php echo $post->user->getAvatarUrl()?>"/>
                                </a>
                            </div>
                            <div class="col-xs-14 action-list">
                                <ul class="list-unstyled">
                                    <li><a href="#" title="Tới trang nhà của <?php echo CHtml::encode($post->user->name)?>" rel="tooltip" class="label label-primary text-medium"><?php echo $post->user->name?></a></li>
                                    <li><abbr title="Ngày tham gia" rel="tooltip" ><i class="fa fa-calendar"></i></abbr> <span class="text-mini text-muted initialism"><?php echo MyDateTime::datetimeFormat($post->user->created, true)?></span></li>
                                    <li><abbr title="Theo dõi, kết bạn với <?php echo CHtml::encode($post->user->name)?>" rel="tooltip" ><i class="fa fa-smile-o"></i></abbr> <a href="#">Follow</a> <span class="text-muted text-mini">(<span class="text-bold">12</span>)</span></li>
                                    <li><abbr title="Nhắn tin tới <?php echo CHtml::encode($post->user->name)?>" rel="tooltip" ><i class="fa fa-comments-o"></i></abbr> <a href="#" rel="tooltip">Nhắn tin</a></li>
                                </ul>                                
                            </div>
                        </div>
                    </div>
                    <div class="col-sm-16 info-list">

                        <?php if($post->user->phone_main):?>
                            <div class="row">
                                <label class="col-lg-4 col-sm-6 col-xs-7 control-label text-right">ĐT liên hệ</label>
                                <div class="col-lg-20 col-sm-18 col-xs-17 value"><?php echo $post->user->phone_main->phone?></div>
                            </div>
                            <?php endif?>
                        <?php if($post->addressFull):?>
                            <div class="row">
                                <label class="col-lg-4 col-sm-6 col-xs-7 control-label text-right">Địa chỉ</label>
                                <div class="col-lg-20 col-sm-18 col-xs-17 value"><?php echo $post->addressFull?></div>
                            </div>
                            <?php endif?>
                        <?php if($post->typeLabel):?>
                            <div class="row">
                                <label class="col-lg-4 col-sm-6 col-xs-7 control-label text-right">Cần</label>
                                <div class="col-lg-20 col-sm-18 col-xs-17 value"><?php echo $post->typeLabel?></div>
                            </div>
                            <?php endif?>
                        <?php if($post->stateLabel):?>
                            <div class="row">
                                <label class="col-lg-4 col-sm-6 col-xs-7 control-label text-right">Tình trạng</label>
                                <div class="col-lg-20 col-sm-18 col-xs-17 value"><?php echo $post->stateLabel?></div>
                            </div>
                            <?php endif?>
                        <?php if($post->price):?>
                            <div class="row">
                                <label class="col-lg-4 col-sm-6 col-xs-7 control-label text-right">Giá</label>
                                <div class="col-lg-20 col-sm-18 col-xs-17 value"><span class="text-danger text-bold"><?php echo $post->priceLabel?></span></div>
                            </div>
                            <?php endif?>
                        <div class="row">
                            <label class="col-lg-4 col-sm-6 col-xs-7 control-label text-right">Đăng lúc</label>
                            <div class="col-lg-20 col-sm-18 col-xs-17 value"><?php echo MyDateTime::datetimeFormat($post->created)?></div>
                        </div>
                        <div class="row">
                            <label class="col-lg-4 col-sm-6 col-xs-7 control-label text-right">Lượt xem</label>
                            <div class="col-lg-20 col-sm-18 col-xs-17 value"><?php echo $post->viewCountLabel?></div>
                        </div>

                    </div>
                </div>
            </div>


            <div class="panel panel-simple">
                <div class="panel-heading success">
                    <h3 class="panel-title"><i class="fa fa-list-alt"></i> Nội dung</h3><span class="panel-under"></span>
                </div>
                <div class="panel-body text-content">
                    <?php echo $post->content?>
                </div>
            </div>


            <?php if($post->image):?>
                <div class="panel panel-simple marginbottom0 margintop10 panel-img-attachment">
                    <div class="panel-heading">
                        <h3 class="panel-title"><i class="fa fa-picture-o"></i> Ảnh đính kèm</h3>
                    </div>
                    <div class="panel-body">
                        <div class="image-gallery">
                            <?php foreach($post->postImages as $image):?>
                                <span class="image-item">
                                    <a href="<?php echo $image->url?>" title="<?php echo $this->domain?>: <?php echo CHtml::encode($post->title)?>" download="<?php echo $image->image?>" data-gallery>
                                        <img src="<?php echo $image->getUrl('small')?>" alt="<?php echo $this->domain?>: <?php echo CHtml::encode($post->title)?>">
                                    </a>
                                </span>
                                <?php endforeach?>
                        </div>
                    </div>
                </div>
                <?php endif?>

            <?php if($post->show_map && $post->latlng):?>
                <div class="panel panel-simple">
                    <div class="panel-heading danger">
                        <h3 class="panel-title"><i class="fa fa-map-marker"></i> Bản đồ</h3><span class="panel-under"></span>
                    </div>
                    <div class="panel-body">
                        <div id="map" class="well" style="width: 100%; height: 300px; margin: 0;">
                            <div style="color: #999999;padding-top: 110px;text-align: center;">
                                <i class="icon-refresh icon-spin"></i> Tải bản đồ
                            </div>
                        </div> 
                    </div>
                </div>
                <?php endif?>

            <div class="panel panel-simple marginbottom0 <?php if(!$postReplyData):?>hide<?php endif?>" id="panel-replies">
                <div class="panel-heading danger">
                    <?php if($postReplyCount >= 5):?>
                        <button id="btn-reply" class="btn btn-primary btn-md pull-right"><i class="fa fa-reply"></i> Gửi trả lời</button>
                        <?php endif?>
                    <h3 class="panel-title">
                        <i class="fa fa-comments-o"></i>
                        Trả lời
                        <span class="panel-under"></span>
                    </h3>
                </div>
                <div class="panel-body" id="panel-body-replies">
                    <?php foreach($postReplyData as $postReply):?>
                        <?php $this->renderPartial('_reply_view', array('postReply' => $postReply))?>
                        <?php if($postReply->childs):?>
                            <?php foreach($postReply->childs as $postReplyChild):?>
                                <?php $this->renderPartial('_reply_view', array('postReply' => $postReplyChild))?>
                                <?php endforeach?>
                            <?php endif?>
                        <?php endforeach;?>
                </div>
            </div>

            <div class="panel panel-simple" id="panel-reply">
                <div class="panel-heading primary">
                    <h3 class="panel-title"><i class="fa fa-pencil-square-o"></i> Gửi trả lời</h3><span class="panel-under"></span>
                </div>
                <div class="panel-body">
                    <div class="row">
                        <div class="col-sm-4 hidden-xs avatar">
                            <a href="#">
                                <img class="thumbnail" src="<?php echo $post->user->getAvatarUrl()?>"/>
                            </a>
                        </div>
                        <div class="col-sm-20 col-xs-24">
                            <?php $form=$this->beginWidget('CActiveForm', array(
                                    'id'=>'post-reply-form',
                                    'enableClientValidation'=>true,
                                    'clientOptions'=>array(
                                        'validateOnSubmit' => true,
                                        'validateOnChange' => true,
                                        'afterValidate' => "js:function(form, data, hasError){
                                        postReplyAfterValidate(form, data, hasError);
                                        }",
                                    ),
                                    'enableAjaxValidation'=>false,
                                    'htmlOptions' => array('class' => '')
                                )); ?>
                            <?php //echo $form->errorSummary($postReplyModel); ?>

                            <div class="alert alert-info" style="display: none;">
                                Gửi trả lời tới <strong id="reply_to_user"></strong>
                                <i id="reply_to_user_remove" title="Bỏ gửi tới thành viên này" rel="tooltip" class="fa fa-remove pull-right" style="cursor: pointer;"></i>
                            </div>

                            <div class="form-group">
                                <?php echo $form->hiddenField($postReplyModel,'reply_id'); ?>
                                <?php echo $form->hiddenField($postReplyModel,'post_id'); ?>
                                <?php echo $form->textArea($postReplyModel,'content', array('style' => 'height: 100px', 'class' => 'editor' .(!$this->user ? ' require-login' : ''))); ?>
                                <?php echo $form->error($postReplyModel,'content');?>
                            </div>  
                            <div class="form-group">
                                <button class="btn btn-primary btn-md pull-left <?php if(!$this->user):?>require-login<?php endif?>" type="submit">
                                    <i class="fa fa-reply"></i> Gửi trả lời
                                </button>

                                <div class="pull-right">
                                    <button type="button" id="reply-advance" rel="<?php echo $this->createUrl('/hangve/post/replyCreate', array('post_id' => $post->id, 'post_alias' => $post->alias))?>" class="btn btn-link <?php if(!$this->user):?>require-login<?php endif?>" style="padding-right: 0px;">
                                        <i class="fa fa-reply-all"></i> Trả lời nâng cao
                                    </button>
                                    <abbr title="Bạn có thể chèn thêm ảnh vào bài viết" rel="tooltip" class="initialism"><i class="fa fa-question-circle"></i></abbr> 
                                </div>
                            </div>
                            <?php $this->endWidget(); ?>
                        </div>
                    </div>
                </div>
            </div>


        </div>
        <div class="col-md-6">
            <?php $this->renderPartial('//common/sidebar')?>
        </div>
    </div>
</div>


<?php if($post->image):?>
    <div id="blueimp-gallery" class="blueimp-gallery blueimp-gallery-controls" data-filter=":even">
        <div class="slides"></div>
        <h3 class="title"></h3>
        <a class="prev">‹</a>
        <a class="next">›</a>
        <a class="close">×</a>
        <a class="play-pause"></a>
        <ol class="indicator"></ol>
    </div>
    <link rel="stylesheet" href="/files/js/blueimp/jquery.gallery/css/blueimp-gallery.min.css">
    <script src="/files/js/blueimp/jquery.gallery/js/jquery.blueimp-gallery.min.js"></script>
    <?php endif?>

<?php if($post->show_map):?>
    <script type="text/javascript" src="<?php echo $this->googleMapURI?>"></script>
    <script type="text/javascript" src="/files/js/google-maps-utility-library-v3/infobox/src/infobox_packed.js"></script> 
    <script>var infoBoxHtml = '<b><?php echo CHtml::encode($post->title)?></b><br><?php echo CHtml::encode($post->addressFull)?>';</script>
    <?php endif?>

<script type="text/javascript" src="/files/editor/tinymce4/tinymce.min.js"></script>



<script type="text/javascript" src="<?php echo $this->themeUrl?>/files/js/post_view.js"></script>
<script>  
    <?php if(!$this->user):?>  
        tinyMceConfig.init_instance_callback = function(){
            tinyMCE.activeEditor.on('focus', function(e) {
                e.preventDefault();
                $('#modal-login').modal();
            });
        };
        <?php endif?>
    tinyMCE.init(tinyMceConfig);
    <?php if($post->show_map):?>google_map('<?php echo $post->latlng?>');<?php endif?> 

    <?php if(!(string)Yii::app()->request->cookies['post_saved']):?> 
        if(typeof(Storage)!=="undefined"){
            delete localStorage.post_content;
        };
        <?php endif?>
</script>












